package com.translate.web.service.impl;

import com.translate.web.config.contract.IOSSConfig;
import com.translate.web.dao.TranslatorsAssociationMapper;
import com.translate.entity.TranslatorsAssociation;
import com.translate.web.service.ITranslatorsAssociationService;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class TranslatorsAssociationServiceImpl extends BaseTranslateServiceImpl<TranslatorsAssociation>
		implements ITranslatorsAssociationService {
	
	private IOSSConfig config;
	
	@Resource
	public void setConfig(IOSSConfig config) {
		this.config = config;
	}

	public TranslatorsAssociationServiceImpl(TranslatorsAssociationMapper mapper) {
		super(mapper);
	}

	protected void insertPropteris(TranslatorsAssociation data) {
		long time = System.currentTimeMillis() / 1000;
		data.setCreateTime(time);
		data.setUpdateTime(time);
	}

	protected void updatePropteris(TranslatorsAssociation data) {
		data.setUpdateTime(System.currentTimeMillis() / 1000);
	}

	protected Class<TranslatorsAssociation> getEntityClass() {
		return TranslatorsAssociation.class;
	}

	@Resource
	public void setRedisTemplate(RedisTemplate<String, ? extends Object> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}

	@Override
	public List<TranslatorsAssociation> listToCache(String cacheKey, int limitNumber) {
		// TODO Auto-generated method stub
		List<TranslatorsAssociation> listToCache = super.listToCache(cacheKey, limitNumber);
		
		if (0 ==listToCache.size()) {
			return listToCache;
		}
		
		String url = "https://".concat(config.getBucketName()).concat(".").concat(config.getEndpoint());
		
		for (TranslatorsAssociation banner : listToCache) {
			banner.setPicUrl(url.concat(banner.getPicUrl()));
		}
		
		
		return listToCache;
	}
	
	
}